package com.xtecher.app.column.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.xtecher.app.column.bean.ColumnResponse;
import com.xtecher.app.column.ui.ColumnFragment;

import java.util.List;

/**
 * Created by Luhao on 2017/2/22.
 */

public class ColumnPageAdapter extends FragmentPagerAdapter {
    private final List<ColumnResponse> coloumns;

    public ColumnPageAdapter(FragmentManager fm, List<ColumnResponse> coloumns) {
        super(fm);
        this.coloumns = coloumns;
    }

    /**
     * Return the Fragment associated with a specified position.
     *
     * @param position
     */
    @Override
    public Fragment getItem(int position) {
        return ColumnFragment.newInstance(coloumns.get(position));
    }

    /**
     * Return the number of views available.
     */
    @Override
    public int getCount() {
        return coloumns.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return coloumns.get(position).getName();
    }
}
